package com.cn.bukeManage.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.cn.bukeManage.utils.kuaiDI.KdApiOrderDistinguish;
import com.cn.bukeManage.utils.kuaiDI.KdniaoTrackQueryAPI;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/kuaiDi")
public class KuaiDiController {

	@RequestMapping("/getKuaiDi")
	@ResponseBody
	public JSONObject getKuaiDi(String LogisticCode){
		KdApiOrderDistinguish api = new KdApiOrderDistinguish();
		KdniaoTrackQueryAPI api2 = new KdniaoTrackQueryAPI();
		String result=null;
		try {
			String wuliuGongsi=api.getOrderTracesByJson(LogisticCode);
			JSONObject jsonObject=JSONObject.parseObject(wuliuGongsi);
			JSONArray jsonArray = jsonObject.getJSONArray("Shippers");
			JSONObject jsonObject2=null;
			if (jsonArray.size()>0) {
				jsonObject2 = jsonArray.getJSONObject(0);
			}
			String string = jsonObject2.getString("ShipperCode");
			result = api2.getOrderTracesByJson(string,LogisticCode);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		JSONObject object=JSONObject.parseObject(result);
		return object;
	}
}
